package com.zhuo.project.k3.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.k3.domain.ZzDepartment;
import com.zhuo.project.k3.mapper.ZzDepartmentMapper;
import com.zhuo.project.k3.service.IZzDepartmentService;

/**
 * 卓正部门信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Service
public class ZzDepartmentServiceImpl implements IZzDepartmentService
{
    @Autowired
    private ZzDepartmentMapper zzDepartmentMapper;

    /**
     * 查询卓正部门信息
     * 
     * @param id 卓正部门信息ID
     * @return 卓正部门信息
     */
    @Override
    public ZzDepartment selectZzDepartmentById(Long id)
    {
        return zzDepartmentMapper.selectZzDepartmentById(id);
    }

    /**
     * 查询卓正部门信息列表
     * 
     * @param zzDepartment 卓正部门信息
     * @return 卓正部门信息
     */
    @Override
    public List<ZzDepartment> selectZzDepartmentList(ZzDepartment zzDepartment)
    {
        return zzDepartmentMapper.selectZzDepartmentList(zzDepartment);
    }

    /**
     * 新增卓正部门信息
     * 
     * @param zzDepartment 卓正部门信息
     * @return 结果
     */
    @Override
    public int insertZzDepartment(ZzDepartment zzDepartment)
    {
        ZzDepartment filter = new ZzDepartment();
        filter.setFnumber(zzDepartment.getFnumber());
        List<ZzDepartment> filterList = zzDepartmentMapper.selectZzDepartmentList(filter);
        if(null != filterList && filterList.size()>0){
            Long id = filterList.get(0).getId();
            zzDepartment.setId(id);
            zzDepartment.setUpdateTime(new Date());
            zzDepartment.setUpdateBy(SecurityUtils.getUsername());
            return zzDepartmentMapper.updateZzDepartment(zzDepartment);
        }
        zzDepartment.setCreateBy(SecurityUtils.getUsername());
        zzDepartment.setCreateTime(new Date());
        return zzDepartmentMapper.insertZzDepartment(zzDepartment);
    }

    /**
     * 修改卓正部门信息
     * 
     * @param zzDepartment 卓正部门信息
     * @return 结果
     */
    @Override
    public int updateZzDepartment(ZzDepartment zzDepartment)
    {
        return zzDepartmentMapper.updateZzDepartment(zzDepartment);
    }

    /**
     * 批量删除卓正部门信息
     * 
     * @param ids 需要删除的卓正部门信息ID
     * @return 结果
     */
    @Override
    public int deleteZzDepartmentByIds(Long[] ids)
    {
        return zzDepartmentMapper.deleteZzDepartmentByIds(ids);
    }

    /**
     * 删除卓正部门信息信息
     * 
     * @param id 卓正部门信息ID
     * @return 结果
     */
    @Override
    public int deleteZzDepartmentById(Long id)
    {
        return zzDepartmentMapper.deleteZzDepartmentById(id);
    }
}
